package TransactionImplementation

import (
	"fmt"
	"log"
	"reflect"
	"strconv"
	"time"
	"SalaryPayment/TransactionApplication"
	"SalaryPayment/DataBase"
	"SalaryPayment/ModelImplementation"
)


type TimeCardTransaction struct {
	itsDate time.Time
	itsHours float64
	itsEmpid int
	TransactionApplication.Transaction
}

func(tct *TimeCardTransaction) Execute() {
	e := DataBase.PayrollDatabase.Default.GetEmployee(tct.itsEmpid)
	
	if e != nil {
		pc := e.GetClassification()

		if reflect.TypeOf(pc) == reflect.TypeOf(ModelImplementation.HourlyClassification) {
			hc := pc.(*ModelImplementation.HourlyClassification)
			hc.AddTimeCard(ModelImplementation.NewTimeCard(tct.itsDate, tct.itsHours))
		} else {
			log.Println(fmt.Errorf(DataBase.PayrollExceptionMessage.NotHoulyClassification + strconv.Itoa(e.GetEmpid)))
		}
	} else {
		log.Println(fmt.Errorf(DataBase.PayrollExceptionMessage.EmployeeNotExist + strconv.Itoa(e.GetEmpid)))
	}
}